//
//  BKUserStatusInfo.m
//  bestkeep
//
//  Created by windCould on 16/11/17.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKUserStatusInfo.h"
#import "BKIntegralCommon.h"

@implementation BKUserPayWay



@end

@implementation BKUserStatusInfo

+(BKUserStatusInfo *)currentUser {
    CacheData *cacheData = [CacheData shareInstance];
    
    RLMResults<BKUserStatusInfo*> *results = [cacheData search:[BKUserStatusInfo class]];
    if(results.count > 0) {
        return results.firstObject;
    }
    
    BKUserStatusInfo *info = [[BKUserStatusInfo alloc] init];
    info.isLogin = NO;
    info.userNum = @"";
    info.userPwd = @"";
    info.TGT = @"";
    info.LoginST = @"UTOUU-ST-INVALID";
    info.ServiceST = @"UTOUU-ST-INVALID";
    info.userId = 0;
    info.userName = @"";
    info.realAuth = NO;
    info.roles = @"";
    info.photo = @"";
    info.stockAccountStateName = @"";
    info.visitorCode = @"";
    info.mobBind = @"";
    info.payBind = @"";
    info.job = @"";
    info.vipFlag = @"";
    info.visitorCode = @"";
    info.email = @"";
    info.money = @"";
    info.level = @"";
    info.levelNum = @"";
    info.nickName = @"";
    info.QQbinding = @"0";
    info.wechatBindin = @"0";
    info.unreadMessageNum = @"";
    info.deveiceToken = @"";
    info.userSecretKey = @"";
    info.userValidTime = @"";
    [cacheData addObject:info];
    return info;
}

+(void)clearHistoryData
{
    BKUserStatusInfo * userInf = [BKUserStatusInfo currentUser];
    [userInf.realm beginWriteTransaction];
    
    userInf.isLogin = NO;
    userInf.TGT = @"";
    userInf.ServiceST = @"UTOUU-ST-INVALID";
    userInf.LoginST = @"UTOUU-ST-INVALID";
    userInf.userId = 0;
    userInf.job = @"";
    userInf.email = @"";
    userInf.realAuthStatus = @"";
    userInf.levelNum = @"";
    userInf.vipFlag = @"";
    userInf.photo = @"";
    userInf.userPwd = @"";
    userInf.stockAccountStateName = @"";
    userInf.realAuth = NO;
    userInf.visitorCode = @"";
    userInf.money = @"";
    userInf.payBind = @"";
    userInf.nickName = @"";
    userInf.level = @"";
    userInf.roles = @"";
    userInf.levelNum = @"";
    userInf.realAuthStatus = @"";
    userInf.QQbinding = @"";
    userInf.wechatBindin = @"";
    userInf.unreadMessageNum = @"";
    userInf.userSecretKey = @"";
    for (BKUserPayWay *tempWay in userInf.userPayWays) {
        tempWay.userPayWayName = @"";
        tempWay.userPayWayValue = @"";
    }
    [userInf.userPayWays removeAllObjects];
//    userInf.deveiceToken = @"";
    
    /*
     * 关闭本地推送
     */
    [BKIntegralCommon closeLocalNotification];
    
    [userInf.realm commitWriteTransaction];
    [[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES];
    [[NSNotificationCenter defaultCenter]postNotificationName:UserDidLogoutNotification object:nil];
}

@end
